import Vue from 'vue'
Vue.filter('normalTime', (time = '0', currencyType = '') => {
  if (time) {
    let odate = new Date()
    odate.setTime(time)
    let year = odate.getFullYear()
    let month = odate.getMonth() + 1
    let day = odate.getDate()
    let hours = odate.getHours()
    let minutes = odate.getMinutes()
    let seconds = odate.getSeconds()
    let retime = null
    if (currencyType.format) {
      let format = currencyType.format.split('-')
      for (let i = 0; i < format.length; i++) {
        if (format[i] === '' || typeof (format[i]) === 'undefined') {
          format.splice(i, 1)
          i = i - 1
        }
      }
      format.map(rec => {
        if (rec === 'y') {
          !retime ? retime = year : retime = null
        }
        if (rec === 'M') {
          retime ? retime += currencyType.type + month : retime = month
        }
        if (rec === 'd') {
          retime ? retime += currencyType.type + day : retime = day
        }
        if (rec === 'h') {
          retime ? retime += '  ' + hours : retime = hours
        }
        if (rec === 'm') {
          retime ? retime += currencyType.type + minutes : retime = minutes
        }
        if (rec === 's') {
          retime ? retime += currencyType.type + seconds : retime = seconds
        }
      })
    } else {
      if (currencyType.type) {
        retime = year + currencyType.type + month + currencyType.type + day + '  ' + hours + currencyType.type + minutes
      } else {
        retime = year + '-' + month + '-' + day + '  ' + hours + '-' + minutes
      }
    }
    return retime
  }
})
